package com.ruoyi.admin.service.impl;
import com.ruoyi.admin.service.MemberService;
import com.ruoyi.app.domain.Member;
import com.ruoyi.app.domain.MemberExample;
import com.ruoyi.app.mapper.MemberMapper;
import com.ruoyi.common.core.text.Convert;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.framework.web.domain.AjaxResult;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;
import java.util.Map;

/*
@description:会员服务
@ClassName MemberServiceImpl
@author chen
@create 2025-03-13 17:35
@Version 1.0
*/
@Slf4j
@Service
@AllArgsConstructor
public class MemberServiceImpl implements MemberService
{
    final MemberMapper memberMapper;

    @Override
    public AjaxResult insertSelective(Member member)
    {
        member.setCreateTime(new Date());
        member.setUpdateTime(new Date());
        member.setDisable(false);
        return memberMapper.insertSelective(member) > 0 ? AjaxResult.success() : AjaxResult.error();
    }

    @Override
    public AjaxResult updateByPrimaryKeySelective(Member member)
    {
        member.setUpdateTime(new Date());
        return memberMapper.updateByPrimaryKeySelective(member) > 0 ? AjaxResult.success() : AjaxResult.error();
    }

    @Override
    public AjaxResult selectByPrimaryKey(Long id)
    {
        return AjaxResult.success(memberMapper.selectByPrimaryKey(id));
    }

    @Override
    public List<Member> getMemberList(Map<String, Object> params)
    {
        MemberExample memberExample = null;
        String memberType = Convert.toStr(params.get("memberType"));
        if(StringUtils.isNotEmpty(memberType))
        {
            memberExample = new MemberExample();
            memberExample.createCriteria().andMemberTypeEqualTo(memberType);
        }
        return memberMapper.selectByExample(memberExample);
    }

    @Override
    public AjaxResult deleteByPrimaryKey(Long id)
    {
        return memberMapper.deleteByPrimaryKey(id) > 0 ? AjaxResult.success() : AjaxResult.error();
    }
}
